﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApp
{
    class LinqActionFunc
    {
        public void Show()
        {
            var students= AppDBData.GetDBStudents();
            var studentId3 = students.WhereExt(p => p.id == 3).ToArray();
        }

    }

    public static class Extend
    {
        /// <summary>
        /// 模仿linq的where
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static IEnumerable<T> WhereExt<T>(this IEnumerable<T> source, Func<T, bool> func)
        {
            foreach (var item in source)
            {
                bool res = func(item);
                if (res)
                {
                    yield return item;
                }
            }
        }
    }
    
}
